package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPolicy;
import com.ruoyi.system.service.ISysPolicyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 慢病政策设置Controller
 *
 * @author moweiyu
 * @date 2021-04-30
 */
@Controller
@RequestMapping("/system/policy")
public class SysPolicyController extends BaseController
{
    private String prefix = "system/policy";

    @Autowired
    private ISysPolicyService sysPolicyService;

    @RequiresPermissions("system:policy:view")
    @GetMapping()
    public String policy()
    {
        return prefix + "/policy";
    }

    /**
     * 查询慢病政策设置列表
     */
    @RequiresPermissions("system:policy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysPolicy sysPolicy)
    {
        startPage();
        List<SysPolicy> list = sysPolicyService.selectSysPolicyList(sysPolicy);
        return getDataTable(list);
    }

    /**
     * 导出慢病政策设置列表
     */
    @RequiresPermissions("system:policy:export")
    @Log(title = "慢病政策设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysPolicy sysPolicy)
    {
        List<SysPolicy> list = sysPolicyService.selectSysPolicyList(sysPolicy);
        ExcelUtil<SysPolicy> util = new ExcelUtil<SysPolicy>(SysPolicy.class);
        return util.exportExcel(list, "慢病政策设置数据");
    }

    /**
     * 新增慢病政策设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存慢病政策设置
     */
    @RequiresPermissions("system:policy:add")
    @Log(title = "慢病政策设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysPolicy sysPolicy)
    {
        return toAjax(sysPolicyService.insertSysPolicy(sysPolicy));
    }

    /**
     * 修改慢病政策设置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysPolicy sysPolicy = sysPolicyService.selectSysPolicyById(id);
        mmap.put("sysPolicy", sysPolicy);
        return prefix + "/edit";
    }

    /**
     * 修改保存慢病政策设置
     */
    @RequiresPermissions("system:policy:edit")
    @Log(title = "慢病政策设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysPolicy sysPolicy)
    {
        return toAjax(sysPolicyService.updateSysPolicy(sysPolicy));
    }

    /**
     * 删除慢病政策设置
     */
    @RequiresPermissions("system:policy:remove")
    @Log(title = "慢病政策设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysPolicyService.deleteSysPolicyByIds(ids));
    }
}
